#include "uart_app.h"

ringbuffer_t usart_rb;
uint8_t usart_read_buffer[128];

//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
//	if(huart -> Instance == USART1)
//	{
//		uart_rx_ticks =uwTick;
//		uart_rx_index++;
//		HAL_UART_Receive_IT(&huart1,&uart_rx_buffer[uart_rx_index],1);
//		printf("text");
//	}
//}
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
	  //printf ("dma date:%s\n",uart_rx_dma_buffer);
	if(!ringbuffer_is_full(&usart_rb))
	{
		ringbuffer_write(&usart_rb,uart_rx_dma_buffer,Size);
	}
    memset(uart_rx_dma_buffer, 0, sizeof(uart_rx_dma_buffer));
}

void uart_proc(void)
{
//	if(uart_rx_index == 0) return;
//	if(uwTick - uart_rx_ticks > 100)
//	{
//		printf("uart data:%s\n",uart_rx_buffer);
//		
//		memset(uart_rx_buffer,0,uart_rx_index);
//		uart_rx_index = 0;
//		huart1.pRxBuffPtr = uart_rx_buffer;
//	}
	if(ringbuffer_is_empty(&usart_rb)) return;
	ringbuffer_read(&usart_rb, usart_read_buffer, usart_rb.itemCount);
	printf("ringbuffer data:%s\n",usart_read_buffer);
	memset(uart_rx_buffer,0,sizeof(uint8_t)  * 128);
}









